/*
 *   Copyright (C) 2020,  CentraleSupelec
 *
 *   Author : Jérémy Fix 
 *
 *   Contributor :
 *
 *   This library is free software; you can redistribute it and/or
 *   modify it under the terms of the GNU General Public
 *   License (GPL) as published by the Free Software Foundation; either
 *   version 3 of the License, or any later version.
 *   
 *   This library is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 *   General Public License for more details.
 *   
 *   You should have received a copy of the GNU General Public
 *   License along with this library; if not, write to the Free Software
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 *   Contact : jeremy.fix@centralesupelec.fr
 *
 */

// To be compiled with
// g++ -o process_clint process_clint.cpp -O3 `pkg-config --libs --cflags quantize`

#include <iostream>
#include <fstream>
#include <quantize-cv.hpp>

int main(int argc, char* argv[]) {
	
	if(argc != 2) {
		std::cerr << "Usage " << argv[0] << " imgfile " << std::endl;
		std::cerr << " e.g. " << argv[0] << " ~/.local/share/quantize/clint.jpeg" << std::endl;
		std::exit(EXIT_FAILURE);
	}
	
	// Our compressing algorithm
	constexpr std::size_t num_colors = 10;
	quantize::cv::compressor compressor(num_colors);	

	// Our test image
	cv::Mat img(cv::Size(150, 100), CV_8UC3);
	img = cv::Scalar{255, 255, 255};

	// Add a red gradient
	img = cv::imread(argv[1]); 
	if(img.empty())
	{
		std::cout << "Could not read input image file: " << argv[1] << std::endl;
		std::exit(EXIT_FAILURE);

	}
	cv::imwrite("003_in_image.png", img);	
	std::cout << "003_in_image.png written" << std::endl;

	// Process the image
	auto outimg = compressor.quantize(img);

	// Write the results
	cv::imwrite("003_out_image.png", outimg);	
	std::cout << "003_out_image.png written" << std::endl;
}
